//
//  ReadViewController.m
//  LO_MUSIC
//
//

#import "ReadViewController.h"
#define GETURL @"http://api2.pianke.me/read/columns"

#define POSTURL @"http://api2.pianke.me/ting/radio"
//@{@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":@"",@"version":@"3.0.2"}

@interface ReadViewController ()


@end

@implementation ReadViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
  
    //GET
//    [self GET];
    //POST
    [self POST];
    
    }

-(void)GET {
    
    //GET
    NSURLSession *session = [NSURLSession sharedSession];
    
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:GETURL];
    NSString *urlString = [GETURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //设置请求
    [request setHTTPMethod:@"GET"];
    //
    [request setHTTPBody:nil];
    
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSLog(@"%@",result);
        
    }];
    
    //开启
    [task resume];
    
}

-(void)POST{
    
    //POST
    NSURLSession *session = [NSURLSession sharedSession];
    
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:POSTURL];
    NSString *urlString = [POSTURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //设置请求
    [request setHTTPMethod:@"POST"];
    //设置请求体
    //@{@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":@"",@"version":@"3.0.2"}
    NSString *bodyString = @"client=1&deviceid=63A94D37-33F9-40FF-9EBB-481182338873&auth=&version=3.0.2";
    NSData *data = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    
    NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSLog(@"%@",result);
        
    }];
    
    //开启
    [task resume];
}

@end
